package com.itheima.dao;

import com.itheima.pojo.Member;
import com.itheima.pojo.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface OrderDao {

    @Select("select * from t_order where member_id = #{memberId} and orderDate = #{orderDate} and setmeal_id = #{setmealId}")
    Order findCondition(@Param("memberId") Integer memberId,@Param("orderDate") Date orderDate,@Param("setmealId") int setmealId);

    @Insert("insert into t_order value(null,#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void add(Order order);

    @Select("select m.name member,s.name setmeal,o.orderDate orderDate,o.orderType orderType from t_order o,t_member m,t_setmeal s where o.id=#{orderId} and m.id=o.member_id and s.id = o.setmeal_id")
    Map findById(Integer orderId);

    //今日预约人数
    @Select("select count(id) from t_order where orderDate = #{reportDate}")
    Integer findOrderNumberByToday(String reportDate);

    //今日到诊人数
    @Select("select count(id) from t_order where orderDate = #{reportDate} and orderStatus = '已到诊'")
    Integer findTodayVisitsNumber(String reportDate);


    //本周/本月预约人数
    @Select("select count(id) from t_order where orderDate >= #{reportDate}")
    Integer findAfterOrderNumber(String monday);

    //本周/本月到诊人数
    @Select("select count(id) from t_order where orderDate >= #{reportDate} and orderStatus = '已到诊'")
    Integer findAfterVisitsNumber(String monday);

    //查询当前最热套餐
    @Select("select s.name,count(o.id) setmeal_count,count(o.id)/(select count(id) from t_order) proportion from t_order o,t_setmeal s where s.id=o.setmeal_id group by s.name order by setmeal_count desc limit 0,4")
    List<Map> findHotSetmeal();

}
